package com.example.video.repository;

import com.example.video.domain.DeviceInformation;
import com.example.video.domain.DeviceInformationPK;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;

public interface DeviceInformationRepository extends JpaRepository<DeviceInformation, DeviceInformationPK> {
    void deleteByPk_Device_Id(Long id);

    void deleteByPk_Information_Id(Long id);

    List<DeviceInformation> findByPk_Information_Id(Long id);

    @Query("select DI from DeviceInformation DI where DI.pk.device.imei=:imei and DI.pk.information.publishDate>=:start_time and DI.pk.information.publishDate>=:end_time and DI.pk.information.type=:type and DI.pk.information.isEnable=true")
    List<DeviceInformation> queryInformation(@Param("imei") String imei, @Param("start_time") Date start, @Param("end_time") Date end, @Param("type") Integer type);

    @Query("select DI from DeviceInformation DI where DI.pk.device.imei=:imei and DI.pk.information.publishDate>=:start_time and DI.pk.information.type=:type and DI.pk.information.isEnable=true")
    List<DeviceInformation> queryInformationWithoutEndTime(@Param("imei") String imei, @Param("start_time") Date start, @Param("type") Integer type);
}
